package y24.m1.homework;
public class Test3 {
    public static void main(String[] args) {
        double x = 2;
        double derivative = slope(x);
        System.out.println("函数在x=" + x + "处的导数为：" + derivative);
    }

    public static double slope(double x) {
        double h = 0.00001; // 增量h的值
        double f1 = 2 * (x + h) * (x + h) + 9; // 计算函数在x+h处的值
        double f2 = 2 * (x - h) * (x - h) + 9; // 计算函数在x-h处的值
        double derivative = (f1 - f2) / (2 * h); // 使用差商公式计算导数的值
        return derivative;
    }
}